using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using WebControls;
using BusinessLayer;
using EntityLayer;
using InfraStructureLayer;

public partial class Admin_Parameters : SFPage
{
    busParameters insBusParameters = new busParameters();
    entParameters insEntParameters = new entParameters();
    protected void Page_Load(object sender, EventArgs e)
    {
    }
    protected bool sfgParameters_NeedsDataSource()
    {
        DataTable insDataTableParameters = insBusParameters.SelectParameters();
        if (insBusParameters.HasErrors)
        {
            MessageBoxShow(insBusParameters);
        }
        sfgParameters.SetData(insDataTableParameters);
        return insBusParameters.HasErrors;
    }
    protected void sfgParameters_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        if (e.CommandName == "EditData")
        {
            this.Id = Convert.ToInt32(e.CommandArgument);
            this.OpenEditPanel();
        }
      
    }
    public override void OpenEditPanel()
    {
        this.Clear(this.Master.FindControl("ContentPlaceHolderEdit"));
        base.OpenEditPanel();

        insEntParameters.ParameterId = this.Id;
        insBusParameters.SelectParametersByParameterId(insEntParameters);
        if (insBusParameters.HasErrors)
        {
            MessageBoxShow(insBusParameters);
            return;
        }
        lblParameterNameValue.Text = insEntParameters.ParameterName;
        txtParameterValue.Text = insEntParameters.ParameterValue;
    }

    public override void Save()
    {

        this.Validate();
        if (this.HasErrors)
        {
            MessageBoxShow(this);
            return;
        }

        insEntParameters.ControlTypeId = null;
        insEntParameters.ParameterName = lblParameterNameValue.Text;
        insEntParameters.ParameterValue = txtParameterValue.Text;   
    
        base.Save();
    }
    public override void SaveExisting()
    {
        insEntParameters.ParameterId = this.Id;
        insBusParameters.UpdateParametersByParameterId(insEntParameters);
        if (insBusParameters.HasErrors)
        {
            MessageBoxShow(insBusParameters);
            return;
        }
        base.SaveExisting();
        sfgParameters.LoadGridData();
    }
    protected void btnReset_Click(object sender, EventArgs e)
    {
        CurrentContext.Pages = null;
        CurrentContext.Multilanguage = null;
        CurrentContext.ErrorMessagesMultilanguage = null;
        CurrentContext.Menu = null;
        CurrentContext.Languages = null;
        CurrentContext.Parameters = null;
    }
}
